import { pageSkip } from '@/utils/customTools'
import { myRequest } from '@/utils/requestTools'
import { setLoginInfo } from '@/utils/storeTools'
import { message } from 'antd'

/**
 *  登录接口
 * @param params 请求参数
 * @param callback 请求完成的回调
 */
export const loginApi = (params: { login_name: string; login_password: string }, callback: (suc: boolean, dat?: any) => void) => {
  myRequest({ url: '/authApi/login/login', data: params }, callback)
}

/**
 * 登录
 * @param params 账号, 密码
 */
export const login = (params: { login_name: string; login_password: string }) => {
  loginApi(params, async (suc, dat) => {
    if (suc && dat) {
      setLoginInfo(dat)
      await message.success('登录成功，即将跳转')
      pageSkip('/home')
    }
  })
}
